package com.example.wx.dailyreport.controller;


import com.example.wx.dailyreport.service.UsercollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hulinbo
 * @since 2020-08-08
 */

@RestController
@RequestMapping("/usercollection")
public class UsercollectionController {

    @Autowired
    private UsercollectionService usercollectionService;

    @PostMapping("/updateusercollection")
    public Map<String, Object> usercollection(Integer flag, Integer word_id) {
        Map<String, Object> map = new LinkedHashMap<>();
        String username = (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (usercollectionService.updateUsercollection(flag, username, word_id))
            map.put("status", 200);
        else
            map.put("status", 400);
        return map;
    }

}

